<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="中枢岗工作台">
    <!--suppress ALL -->
     <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/proxy/selectCentralProxyPage">
         <ul class="panel-content">
             <li>
                 <div class="form-actions">
                     <div class="control-group controls span5">
                         <input type="text" class="input-normal  input-pad" name="name"
                                placeholder="请输入关键字搜索">
                     </div>
                     <div class="control-group controls span8">
                         <label class="time-label control-label" style="line-height: 40px;">请选择状态：</label>
                         <select name="status" class="input-normal" id="status">
                             <option value="">请选择状态</option>
                             <option value="">全部状态</option>
                             <option value="等待提交委托书">等待提交委托书</option>
                             <option value="等待指派采样人员">等待指派采样人员</option>
                             <option value="采样中">采样中</option>
                             <option value="等待指派实验人员">等待指派实验人员</option>
                             <option value="实验分析">实验分析</option>
                             <option value="编写报告">编写报告</option>
                             <option value="一审中">一审中</option>
                             <option value="二审中">二审中</option>
                             <option value="发放打印">发放打印</option>
                             <option value="已完成">已完成</option>
                         </select>

                     </div>
                     <button type="submit" class="button  button-primary">
                         查询
                     </button>
                 </div>
             </li>
         </ul>
     </form>
<#----------------------------------------------指派人员表单start--------------------------------------------------------->
<div id="addPeopleContent" style="display:none;">
    <form id="addPeopleForm" class="form-horizontal" action="${basepath}/rest/manage/handlelog/insertCentralHandleLog"
          method="post">
        <input type="hidden" class="input-normal control-text" name="proxyID" id="appointID"/>
        <input type="hidden" class="input-normal control-text" name="status" id="appointStatus"/>
        <div class="row">
            <div class="control-group" id="actionName-group">
                <label class="control-label span16">
                    执行动作：
                </label>
                <div class="controls bui-form-group-select">
                    <select class="span7" name="actionName" id="actionPeopleName">
                        <option>请选择执行动作</option>
                        <option value="提交">提交</option>
                        <option value="回退">回退</option>
                    </select>
                </div>
            </div>
            <div class="control-group span16" id="assigned-people">
                <label class="control-label">选择指派人员：</label>

                <div class="controls bui-form-group-select">
                    <div id="send-people" class="people">
                        <input type="hidden" id="send-peopleName" name="userID">
                    </div>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label">
                    留言备注：
                </label>
                <div class="controls  control-row-auto " style="margin-left: 0px;">
                    <textarea name="remark" placeholder="请输入内容" class="span7"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------指派人员表单 end---------------------------------------------------------->
<#----------------------------------------------实验人员表单start--------------------------------------------------------->
<div id="addTestPeopleContent" style="display:none;">
    <form id="addTestPeopleForm" class="form-horizontal"
          action="${basepath}/rest/manage/handlelog/insertCentrallHandleLog" method="post">
        <input type="hidden" class="input-normal control-text" name="proxyID" id="testID"/>
        <input type="hidden" class="input-normal control-text" name="status" id="testStatus"/>
        <div class="row">
            <div class="control-group" id="testName-group">
                <label class="control-label span16">
                    执行动作：
                </label>
                <div class="controls bui-form-group-select">
                    <select class="span7" name="actionName" id="testPeopleName">
                        <option>请选择执行动作</option>
                        <option value="提交">提交</option>
                        <option value="回退">回退</option>
                    </select>
                </div>
            </div>
            <div class="control-group span16" id="test-people">
                <label class="control-label">选择指派人员：</label>

                <div class="controls bui-form-group-select">
                    <div id="test1-people" class="people">
                        <input type="hidden" id="test-peopleName" name="userID">
                    </div>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label">
                    留言备注：
                </label>
                <div class="controls  control-row-auto " style="margin-left: 0px;">
                    <textarea name="remark" placeholder="请输入内容" class="span7"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------实验人员表单 end---------------------------------------------------------->
<#----------------------------------------------变更采集人员表单start--------------------------------------------------------->
<div id="changePeopleContent" style="display:none;">
    <form id="changePeopleForm" class="form-horizontal" action="${basepath}/rest/manage/handlelog/changeCollector"
          method="post">
        <input type="hidden" class="input-normal control-text" name="proxyID" id="changeId"/>
        <input type="hidden" class="input-normal control-text" name="status" id="changeStatus"/>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">选择指派人员：</label>

                <div class="controls bui-form-group-select">
                    <div id="change-people" class="people">
                        <input type="hidden" id="change-peopleName" name="userID">
                    </div>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label">
                    留言备注：
                </label>
                <div class="controls  control-row-auto " style="margin-left: 0px;">
                    <textarea name="remark" placeholder="请输入内容" class="span7"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------变更采集人员表单 end---------------------------------------------------------->
<#----------------------------------------------发送打印表单start--------------------------------------------------------->
<div id="completePeopleContent" style="display:none;">
    <form id="completePeopleForm" class="form-horizontal"
          action="${basepath}/rest/manage/handlelog/insertCentralHandleLogs" method="post">
        <input type="hidden" class="input-normal control-text" name="proxyID" id="completeID"/>
        <input type="hidden" class="input-normal control-text" name="status" id="completeStatus"/>
        <div class="row">
            <div class="control-group">
                <label class="control-label span16">
                    执行动作：
                </label>
                <div class="controls bui-form-group-select">
                    <select class="span7" name="actionName" data-rules="{required : true}">
                        <option value="">请选择执行动作</option>
                        <option value="完成">完成</option>
                        <option value="回退">回退</option>
                    </select>
                </div>
            </div>
            <div class="control-group span16">
                <label class="control-label">
                    留言备注：
                </label>
                <div class="controls  control-row-auto " style="margin-left: 0px;">
                    <textarea name="remark" placeholder="请输入内容" class="span7"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------发送打印表单 end---------------------------------------------------------->
<div id="grid"></div>
<script>
    //查询登陆用户的名称
    var userID = "", isHeadman = "";
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/rest/manage/user/selectLoginUser',
        success: function (data) {
            userID = data.data.id;
            isHeadman = data.data.isHeadman;
            query();
        }
    })
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            Select = BUI.Select, columns = "", store = "", grid = "";

    function query() {
        columns = [
            {
                title: '序号',
                elCls: 'center',
                dataIndex: 'id',
                width: '5%',
                renderer: function (value, obj, index) {
                    return index + 1;
                }
            },

            {
                title: '委托书名称', dataIndex: 'name', elCls: 'center', width: '10%', renderer: function (value, obj) {
                    return '<a href="${basepath}/rest/manage/proxy/toProxyDetail?id=' + obj.id + '">' + value + '</a>';
                }
            },
            {title: '委托书编号', dataIndex: 'sno', elCls: 'center', width: '10%'},
            {title: '收到时间', dataIndex: 'updateTime', elCls: 'center', width: '10%'},
            {
                title: '事件跟踪', dataIndex: 'id', elCls: 'center', width: '10%', renderer: function (value) {
                    return '<a href="${basepath}/rest/manage/proxy/toEventList?proxyID=' + value + '">查看</a>';
                }
            },
            {
                title: '采集人员 ', dataIndex: 'collector', elCls: 'center', width: '20%', renderer: function (value) {
                    return value == "" || value == null ? "____" : value;
                }
            },
            {
                title: '当前状态',
                dataIndex: 'status',
                elCls: 'center',
                width: '15%',
                renderer: function (value) {
                    switch (value) {
                        case '等待提交委托书':
                            return '等待提交委托书';
                            break;
                        case '等待指派采样人员':
                            return '等待指派采样人员';
                            break;
                        case '采样中':
                            return '采样中';
                            break;
                        case '等待指派实验人员':
                            return '等待指派实验人员';
                            break;
                        case '实验分析':
                            return '实验分析';
                            break;
                        case '编写报告':
                            return '编写报告';
                            break;
                        case '一审中':
                            return '一审中';
                            break;
                        case '二审中':
                            return '二审中';
                            break;
                        case '发放打印':
                            return '发放打印';
                            break;
                        case '已完成':
                            return '已完成';
                            break;
                    }
                }
            },
            {
                title: '留言备注', dataIndex: 'remark', elCls: 'center', width: '10%', renderer: function (value) {
                    return value == "" || value == null ? "____" : value;
                }
            },
            {
                title: '操作', elCls: 'center', dataIndex: 'id', width: '10%', renderer: function (value, obj) {
                    switch (obj.status) {
                        case '等待提交委托书':
                            return '<a href="javascript:operating(' + value + ',\'' + obj.status + '\')">操作</a>';
                            break;
                        case '等待指派采样人员':
                            return '<a href="javascript:operating(' + value + ',\'' + obj.status + '\')">操作</a>';
                            break;
                        case '采样中':
                            return '<a href="javascript:changePeople(' + value + ',\'' + obj.status + '\')">变更采集人员</a>';
                            break;
                        case '等待指派实验人员':
                            return '<a href="javascript:operatingTest(' + value + ',\'' + obj.status + '\')">操作</a>&nbsp;&nbsp;<a href="javascript:changePeople(' + value + ')">变更采集人员</a>';
                            break;
                        case '实验分析':
                            return '<a href="javascript:changePeople(' + value + ',\'' + obj.status + '\')">变更采集人员</a>';
                            break;
                        case '编写报告':
                            return '<a href="javascript:changePeople(' + value + ',\'' + obj.status + '\')">变更采集人员</a>';
                            break;
                        case '一审中':
                            return '<a href="javascript:changePeople(' + value + ',\'' + obj.status + '\')">变更采集人员</a>';
                            break;
                        case '二审中':
                            return '<a href="javascript:changePeople(' + value + ',\'' + obj.status + '\')">变更采集人员</a>';
                            break;
                        case '发放打印':
                            return '<a href="javascript:completeBtn(' + value + ',\'' + obj.status + '\')">操作</a>&nbsp;&nbsp;<a href="javascript:changePeople(' + value + ',\'' + obj.status + '\')">变更采集人员</a>';
                            break;
                        case '已完成':
                            return '____';
                            break;
                    }

                }
            }
        ];
        var url = "";
        isHeadman == 'n' ? url = '/rest/manage/proxy/selectCentralProxyPage?userID=' + userID + '' : url = '/rest/manage/proxy/selectCentralProxyPage'
        store = new Store({
            url: url,
            autoLoad: true, //自动加载数据
            params: { //配置初始请求的参数
                length: '10',
                status: $("#status").val()
            },
            pageSize: 10,	// 配置分页数目
            root: 'list',
            totalProperty: 'total'
        });
        grid = new Grid.Grid({
            render: '#grid',
            columns: columns,
            loadMask: true, //加载数据时显示屏蔽层
            store: store,
            plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
            // 底部工具栏
            bbar: {
                pagingBar: true
            }
        });

        grid.render();
    }

    /**********************模糊搜索*************************/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });

    /*********************************指派人员的操作***********************************/
    function operating(id, status) {
        addPeopleForm.clearFields();
        addPeopleDialog.show();
        $("#appointID").val(id);
        $("#appointStatus").val(status);
    }

    $("#actionPeopleName").change(function () {
        var type = $(this).val(), html = "";
        if (type == '提交') {
            $("#assigned-people").remove();
            html = '<div class="control-group span16" id="assigned-people"><label class="control-label">选择指派人员：</label>' +
                    '<div class="controls bui-form-group-select"><div id="send-people" class="people"><input type="hidden" id="send-peopleName"  name="userID" data-rules="{required : true}">' +
                    '</div></div></div>';
            $("#actionName-group").after(html);
            queryPeopleName();
        } else {
            $("#assigned-people").remove();
        }
    })
    var addPeopleForm = new BUI.Form.Form({
        srcNode: '#addPeopleForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addPeopleDialog.close();
        }
    }).render();

    var addPeopleDialog = new BUI.Overlay.Dialog({
        title: '操作',
        width: 500,
        height: 280,
        contentId: 'addPeopleContent',
        success: function () {
            if (addPeopleForm.isValid()) {
                addPeopleForm.submit();
            } else {
                addPeopleForm.valid();
            }
        }
    });

    /*********************************指派人员的多选框查询人员***********************************/
    function queryPeopleName() {
        var pStore = new Store({
            url: '${basepath}/rest/manage/user/selectAllList?role_name=采集组&isHeadman=n',
            autoLoad: true,
            root: 'data',
        });
        var pSelect = new Select.Select({
            render: '#send-people',
            valueField: '#send-peopleName',
            list: {
                itemTpl: '<li class="bui-list-item"><span class="x-checkbox"></span>{nickname}</li>',
                idField: 'id'
            },
            multipleSelect: true,
            store: pStore
        }).render();
    }

    queryPeopleName();

    /*********************************实验人员的操作***********************************/
    function operatingTest(id, status) {
        addTestPeopleForm.clearFields();
        addTestPeopleDialog.show();
        $("#testID").val(id);
        $("#testStatus").val(status);
    }

    $("#testPeopleName").change(function () {
        var type = $(this).val(), html = "";
        if (type == '提交') {
            $("#test-people").remove();
            html = '<div class="control-group span16" id="test-people"><label class="control-label">选择指派人员：</label>' +
                    '<div class="controls bui-form-group-select"><div id="test1-people" class="people"><input type="hidden" id="test-peopleName"  name="userID" data-rules="{required : true}">' +
                    '</div></div></div>';
            $("#testName-group").after(html);
            queryTestPeople();
        } else {
            $("#test-people").remove();
        }
    })
    var addTestPeopleForm = new BUI.Form.Form({
        srcNode: '#addTestPeopleForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addTestPeopleDialog.close();
        }
    }).render();

    var addTestPeopleDialog = new BUI.Overlay.Dialog({
        title: '操作',
        width: 500,
        height: 280,
        contentId: 'addTestPeopleContent',
        success: function () {
            if (addTestPeopleForm.isValid()) {
                addTestPeopleForm.submit();
            } else {
                addTestPeopleForm.valid();
            }
        }
    });

    /*********************************实验人员的多选框查询人员***********************************/
    function queryTestPeople() {
        var pStore = new Store({
            url: '${basepath}/rest/manage/user/selectAllList?role_name=实验组&isHeadman=n',
            autoLoad: true,
            root: 'data',
        });
        var pSelect = new Select.Select({
            render: '#test1-people',
            valueField: '#test-peopleName',
            list: {
                itemTpl: '<li class="bui-list-item"><span class="x-checkbox"></span>{nickname}</li>',
                idField: 'id'
            },
            multipleSelect: true,
            store: pStore
        }).render();
    }

    queryTestPeople();

    /*********************************变更采集人员***********************************/
    function changePeople(id, status) {
        changePeopleForm.clearFields();
        changePeopleDialog.show();
        $("#changeId").val(id);
        $("#changeStatus").val(status);
    }

    var changePeopleForm = new BUI.Form.Form({
        srcNode: '#changePeopleForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            changePeopleDialog.close();
        }
    }).render();

    var changePeopleDialog = new BUI.Overlay.Dialog({
        title: '变更采集人员',
        width: 500,
        height: 240,
        contentId: 'changePeopleContent',
        success: function () {
            if (changePeopleForm.isValid()) {
                changePeopleForm.submit();
            } else {
                changePeopleForm.valid();
            }
        }
    });

    /*********************************变更人员的多选框查询人员***********************************/
    function queryChangePeople() {
        var pStore = new Store({
            url: '${basepath}/rest/manage/user/selectAllList?role_name=采集组&isHeadman=n',
            autoLoad: true,
            root: 'data',
        });
        var pSelect = new Select.Select({
            render: '#change-people',
            valueField: '#change-peopleName',
            list: {
                itemTpl: '<li class="bui-list-item"><span class="x-checkbox"></span>{nickname}</li>',
                idField: 'id'
            },
            multipleSelect: true,
            store: pStore
        }).render();
    }

    queryChangePeople();

    /*********************************确定项目是否完成**********************************/
    function completeBtn(id, status) {
        completePeopleForm.clearFields();
        completePeopleDialog.show();
        $("#completeID").val(id);
        $("#completeStatus").val(status);
    }

    var completePeopleForm = new BUI.Form.Form({
        srcNode: '#completePeopleForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            completePeopleDialog.close();
        }
    }).render();

    var completePeopleDialog = new BUI.Overlay.Dialog({
        title: '操作',
        width: 500,
        height: 240,
        contentId: 'completePeopleContent',
        success: function () {
            if (completePeopleForm.isValid()) {
                completePeopleForm.submit();
            } else {
                completePeopleForm.valid();
            }
        }
    });
</script>

</@page.pageBase>
